
import {Component} from '@angular/core';

import {NavController, Platform} from 'ionic-angular';
import {Reddit} from "../../providers/reddit";
import {Data} from "../../providers/data";
import {FormControl} from "@angular/forms";
import {Keyboard} from "ionic-native";

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  subredditValue: string;
  subredditControl: FormControl;

  constructor(public navCtrl: NavController, public redditService: Reddit, public DataService: Data,
              public platform: Platform) {
    this.subredditControl = new FormControl();
  }

  ionViewDidLoad() {
    this.subredditControl
      .valueChanges
      .debounceTime(1500)
      .distinctUntilChanged().subscribe(subreddit => {
      if (subreddit != '' && subreddit) {
        this.redditService.subreddit=subreddit;
        this.changeSubreddit();
        Keyboard.close();
      }
    });


    this.platform.ready().then(() => {
      this.loadSettings();
    })
  }

  loadSettings(): void {

  }

  showComments(post): void {
    console.log("TODO: Implement showComments()");
  }

  openSettings(): void {
    console.log("TODO: Implement openSettings()");
  }

  playVideo(e, post): void {
    console.log("TODO: Implement playVideo()");
  }

  changeSubreddit(): void {
    console.log("TODO: Implement changeSubreddit()");
  }

  loadMore(): void {
    console.log("TODO: Implement loadMore()");
  }
}
